package com.ruoyi.project.web.videoClassify.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.web.videoClassify.domain.VideoClassify;
import com.ruoyi.project.web.videoClassify.service.IVideoClassifyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 视频分类Controller
 * 
 * @author ruoyi
 * @date 2021-01-21
 */
@Controller
@RequestMapping("/web/videoClassify")
public class VideoClassifyController extends BaseController
{
    private String prefix = "web/videoClassify";

    @Autowired
    private IVideoClassifyService videoClassifyService;

    @RequiresPermissions("web:videoClassify:view")
    @GetMapping()
    public String videoClassify()
    {
        return prefix + "/videoClassify";
    }

    /**
     * 查询视频分类列表
     */
    @RequiresPermissions("web:videoClassify:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VideoClassify videoClassify)
    {
        startPage();
        List<VideoClassify> list = videoClassifyService.selectVideoClassifyList(videoClassify);
        return getDataTable(list);
    }

    /**
     * 导出视频分类列表
     */
    @RequiresPermissions("web:videoClassify:export")
    @Log(title = "视频分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VideoClassify videoClassify)
    {
        List<VideoClassify> list = videoClassifyService.selectVideoClassifyList(videoClassify);
        ExcelUtil<VideoClassify> util = new ExcelUtil<VideoClassify>(VideoClassify.class);
        return util.exportExcel(list, "videoClassify");
    }

    /**
     * 新增视频分类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存视频分类
     */
    @RequiresPermissions("web:videoClassify:add")
    @Log(title = "视频分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VideoClassify videoClassify)
    {
        return toAjax(videoClassifyService.insertVideoClassify(videoClassify));
    }

    /**
     * 修改视频分类
     */
    @GetMapping("/edit/{classifyId}")
    public String edit(@PathVariable("classifyId") Long classifyId, ModelMap mmap)
    {
        VideoClassify videoClassify = videoClassifyService.selectVideoClassifyById(classifyId);
        mmap.put("videoClassify", videoClassify);
        return prefix + "/edit";
    }

    /**
     * 修改保存视频分类
     */
    @RequiresPermissions("web:videoClassify:edit")
    @Log(title = "视频分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VideoClassify videoClassify)
    {
        return toAjax(videoClassifyService.updateVideoClassify(videoClassify));
    }

    /**
     * 删除视频分类
     */
    @RequiresPermissions("web:videoClassify:remove")
    @Log(title = "视频分类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(videoClassifyService.deleteVideoClassifyByIds(ids));
    }

    @PostMapping( "/checkClassifyNameUnique")
    @ResponseBody
    public int checkClassifyNameUnique(VideoClassify videoClassify)
    {
        return videoClassifyService.checkClassifyNameUnique(videoClassify);
    }
}
